<template>
  <div>
    <ul class="shopcar">
      <li v-for="(item,index) in $store.state.shopCarList" :key="index">
        <div class="check" @click="checkimg(item)">
          <img
            :src="item.check?'https://res.bestcake.com/m-images/order/mw_firm_duihao_1.jpg':'https://res.bestcake.com/m-images/order/mw_firm_duihao_2.jpg'"
            alt
          />
        </div>
        <div class="shopcarlist_img">
          <img :src="item.img" alt />
        </div>
        <div class="shopcarlist_info">
          <div class="itemname">{{item.Name|textLengthSet(9)}}</div>
          <div class="itemsize">{{item.Gram}}({{item.Size}})</div>
          <div class="itemprice">{{item.CurrentPrice}}</div>
        </div>
        <div class="count">
          <div>
            <span class="del" @click="del(item)">-</span>
            <span class="num">{{item.num}}</span>
            <span class="add" @click="add(item)">+</span>
          </div>
        </div>
      </li>
    </ul>
    <div class="settle_accounts">
      <div class="img" @click="allsalecheck">
        <img
          :src="$store.getters.allcheck.length==$store.state.shopCarList.length?'https://res.bestcake.com/m-images/order/mw_firm_duihao_1.jpg':'https://res.bestcake.com/m-images/order/mw_firm_duihao_2.jpg'"
          alt
        />
      </div>
      <div class="quanxaun">
        <span>全选/反选</span>
      </div>
      <div class="clear" @click="qingkong">
        <span>清空</span>
      </div>
      <div class="jisuan">
        <div>合计:{{this.$store.getters.count}}</div>
        <div><a href="http://baidu.com">以优惠:</a></div>
      </div>
      <div class="jiesuan" @click="jiesuan()">结算</div>
    </div>
    <div class="wuyong"></div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      shopCarList: [],
      num: 1,
      saleList: []
    };
  },
  mounted() {
    console.log(this.$store);
    // this.shopCarList = this.$store.state.shopCarList;
  },
  methods: {
    checkimg(value) {
      this.$store.commit("shopcarcheck", value);
    },
    add(item) {
      this.$store.commit("shopcaradd", item);
    },
    del(item) {
      this.$store.commit("shopcardel", item);
    },
    allsalecheck() {
      this.$store.commit("allshopcarList");
    },
    jiesuan() {
      if (this.$store.getters.allcheck.length == 0) {
        this.$message.error("还没有选择下单的商品");
      } else {
        this.$confirm(
          `现在跳转到结算页面一共商品的数目为${this.$store.getters.allcheck.length}件`,
          "提示",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "success "
          }
        )
          .then(() => {
            this.$message({
              type: "success",
              message: "success!"
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消"
            });
          });
      }
    },
    qingkong(){
     
        this.$confirm('是否清空购物车?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            this.$store.commit("clearshopCarList");
          this.$message({
            type: 'success',
            message: '清除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消清除'
          });          
        });
     
    }
  },
  computed: {},
  watch: {}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style  lang='scss'>
.el-message-box {
  width: r(240);
}
.shopcarlist_img {
}
.settle_accounts {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: r(56);
  border-top: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  position: fixed;
  bottom: r(54);
  background: #fff;
  .jisuan {
    margin-top: r(10);
  }
  .quanxaun {
    line-height: r(56);
  }
  .clear {
    line-height: r(56);
  }
  .img {
    line-height: r(56);
    display: inline-block;
    padding-left: r(7);
    width: r(25);
    img {
      width: r(18);
      height: r(18);
      display: inline-block;
    }
  }
  .quanxaun {
    width: r(60);
  }
  .clear {
    width: r(25);
  }
  .jisuan {
    width: r(70);
  }
  .jiesuan {
    width: r(120);
    display: block;
    background: #02d4d7;
    color: #fff;
    font-weight: bolder;
    text-align: center;
    line-height: r(56);
    font-size: larger;
  }
}
.wuyong {
  height: r(100);
}
.shopcar {
  li {
    display: flex;
    justify-content: space-around;
    .shopcarlist_info {
      .itemname {
        height: r(30);
        line-height: r(50);
      }
      .itemsize {
        color: #ccc;

        line-height: r(40);
      }
      .itemprice {
        color: #030303;
        font-weight: bold;
      }
    }
    .check {
      line-height: r(115);

      display: inline-block;
      img {
        width: r(18);
        height: r(18);
        display: inline-block;
      }
    }
    .count {
      line-height: r(115);

      display: inline-block;
      .del {
        width: r(22);
        height: r(22);
        line-height: r(22);
        display: inline-block;
        text-align: center;
        font-size: r(18);
      }
      .add {
        width: r(22);
        height: r(22);
        line-height: r(22);
        display: inline-block;
        text-align: center;
        font-size: r(18);
      }
      .num {
        width: r(22);
        height: r(22);
        line-height: r(22);
        display: inline-block;
        text-align: center;
        font-size: r(15);
      }
    }
    .shopcarlist_img {
      img {
        width: r(115);
        height: r(115);
      }
    }
    .shopcarlist_info {
      .itemname {
        font-size: r(16);
      }
    }
  }
}
</style>


